<?php
	session_start();
	date_default_timezone_set("UTC");
	
	$ticket_parent=1;
	
	require("auth.php");
	
	if(!is_admin()){
		header('Location: class_manager.php');
		exit;
	}
	
	$errors = array();
	$warnings = array();
	$status = array();

	require("dbconnect.php");
	require("functions.php");
	
	if(!isset($_GET["participant"])){
		e("No participant specified.");
	}
	else{
		$participant_pkey = trim($_GET["participant"]);
		if(strlen($participant_pkey)==0){
			e("No participant specified.");
		}
		else if(filter_var($participant_pkey, FILTER_VALIDATE_INT) === false || $participant_pkey<0){
			e("Participant number has invalid format.");
		}
		else{
			$result = mysql_query("SELECT character_name, payment_code FROM `participants` WHERE pkey=$participant_pkey", $class_manager_db) or die(mysql_error($class_manager_db));
			if(mysql_num_rows($result)<=0){
				e("Participant does not exist.");
			}
			else{
				$line=mysql_fetch_array($result, MYSQL_ASSOC);
				$character_name=htmlspecialchars(stripslashes($line["character_name"]));
				$payment_code=$line["payment_code"];
				if($payment_code===NULL){
					e("Participant has no payment code.");
				}
			}
		}
	}
	
	
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Payment Details - <?php echo $character_name;?></title>
		<link rel="stylesheet" href="styles/style.css" media="screen" />
	</head>

	<body>
		<?php 
		if(!empty($errors)){
		?>
			<table class="top-level">
				<tr class="err">
					<td width="60px" valign="top">
						<img alt="Error" src="images/error.png" width="60px" height="60px" />
					</td>
					<td valign="top" align="left">
						<ul style="padding:0;margin:0px 0px 8px 16px;">
							<?php foreach ($errors as $msg) { ?><li><?=$msg; ?></li><?php } ?>
						</ul>
					</td>
				</tr>
			</table>
		<?php
		}
		else{
		?>
			<div class="present">
			<h2 class="spaced">Payment Details - <?php echo $character_name;?></h2>
			<span style="max-width:400px;word-wrap:break-word;">==!<?php echo $payment_code; ?></span>
			<table>
				<tr>
					<td><h4>Date/Time</h4></td>
					<td><h4>Forum Name</h4></td>
					<td><h4>Character Name</h4></td>
					<td><h4>Amount</h4></td>
					<td><h4>Comments</h4></td>
				</tr>
<?php 
$result = mysql_query("SELECT *, UNIX_TIMESTAMP(timestamp) as unix_timestamp FROM transactions WHERE payment_code='$payment_code' order by timestamp desc", $class_manager_db) or die(mysql_error($class_manager_db));
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
				<tr>
					<td valign="top"><?php echo date("d M Y, H:i:s",$line["unix_timestamp"]);?></td>
					<td valign="top"><?php if($line["forum_member_id"]!==NULL) echo htmlspecialchars(stripslashes("GET FORUM NAME"));?></td>
					<td valign="top"><?php if($line["character_name"]!==NULL) echo htmlspecialchars(stripslashes($line["character_name"]));?></td>
					<td valign="top"><?php echo number_format($line["amount"],2);?></td>
					<td valign="top" style="max-width:75px;word-wrap:break-word;"><?php echo htmlspecialchars(stripslashes($line["comments"]));?></td>
				</tr>
				
<?php 
}
?>
			</table>
			</div>
		
		
		
		
		
		
		
		<?php
		}
		?>
		
	</body>
	
</html>
